#ifndef A1D7758D_89DE_449D_BBC3_4B038883E4F0
#define A1D7758D_89DE_449D_BBC3_4B038883E4F0


#include <iostream>
#include <unistd.h>
#include <fstream>
#include <cstring>
#include <unordered_map>
#include "Log.hpp"

extern Log lg;

const std::string pathname = "dict.txt";
const std::string sep = ":";

bool Spilit(const std::string& s,std::string* part1,std::string* part2)
{
	auto pos = s.find(sep);
	if(pos == std::string::npos) return false;
	*part1 = s.substr(0,pos);
	*part2 = s.substr(pos+1);
	return true;
}

class Init{
public:
	Init()
	{
		std::ifstream in(pathname);
		if(!in.is_open()){
			lg(Fatal,"file open error,error:%d,errstring:%s",errno,strerror(errno));
			return;
		}
		std::string line;
		while(std::getline(in,line))
		{
			std::string part1,part2;
			Spilit(line,&part1,&part2);
			dict[part1] = part2;
		}
		in.close();
	}
	std::string translation(const std::string& s)
	{
		auto it = dict.find(s);
		if(it == dict.end()) return "Unknown";
		return dict[s];
	}
private:
	std::unordered_map<std::string,std::string> dict;
};

#endif /* A1D7758D_89DE_449D_BBC3_4B038883E4F0 */
